package cn.edu.cdu.farmdeal.controller;

import cn.edu.cdu.farmdeal.service.CartService;
import cn.edu.cdu.farmdeal.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author: tupeng
 * @Date: 2020/3/15
 **/
@Controller
public class CartController {
    @Autowired
    private CartService cartService;

    @RequestMapping("cart/getCart")
    @ResponseBody
    public R getCart(String userName){
        return R.ok().put("data",cartService.getCart(userName));
    }

    @PostMapping("cart/plusCart")
    @ResponseBody
    public R plusCart(@RequestParam("id") String id,@RequestParam("price") String price){
        return R.ok().put("data",cartService.plusCart(id,price));
    }

    @PostMapping("cart/reduceCart")
    @ResponseBody
    public R reduceCart(@RequestParam("id") String id,@RequestParam("price") String price){
        return R.ok().put("data",cartService.reduceCart(id,price));
    }

    @PostMapping("cart/deleteCart")
    @ResponseBody
    public R deleteCart(String id){
        cartService.deleteCart(id);
        return R.ok();
    }


}
